import {getLocal} from "../../utils/local";
import {MyMap} from "../../utils/lodash";

export async function deleteImage(item) {
    var userImageDao = new AV.Object('userImage')
    userImageDao.id = item.objectId
    var result = await  userImageDao.destroy()
    return result
}

export async function getAllUserImage({limit, offset}) {
    var userImageDao = new AV.Query('userImage')
    var user = getLocal("app.login_user")
    var userDao = new AV.Object.createWithoutData('user', user.objectId)
    var results = (await userImageDao.equalTo('user', userDao).skip(offset).limit(limit).addDescending('createdAt').find());
    return MyMap(results, item => item.toJSON())
}